// pages/project/forDisplay/forDisplay.js
Page({
  data: {
    //hiddenmodalput: true,
    max_num:0,
    award:'',
    captainName:'',
    innovation:'',
    institute:'',
    introduction:'',
    major:'',
    memberFiveGrade	:'',
    memberFiveMajor:'',
    memberFiveName:'',
    memberFourGrade:'',
    memberFourMajor	:'',
    memberFourName:'',
    memberOneGrade:'',
    memberOneMajor:'',
    memberOneName	:'',
    memberThreeGrade:'',
    memberThreeMajor:'',
    memberThreeName	:'',
    memberTwoGrade:'',
    memberTwoMajor:'',
    memberTwoName	:'',
    name:'',
    number:'',
    paper:'',
    teacherApartment:'',
    teacherOneApartment: "",
    teacherOneName: "",
    teacherOneRank: "",
    teacherOneStudy: "",
    teacherTwoApartment: "",
    teacherTwoName: "",
    teacherTwoRank: "",
    teacherTwoStudy: "",
    type:'创新训练项目',
    year:'',
    sessionID:'',
    institute:'',
    captainName:'',
    displayId:'',
    recruitProjectId:'',
    projectType:'',
    file: "",
    file2: "",
    file2Name: "",
    fileName: "",
    file1Name: "",
    fileNum:0,
    fileData:''
  },
   /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('options',options)
    this.setData({
      name : options.name,
      sessionID: wx.getStorageSync('sessionID'),
      captainName: options.captain,
      institute: options.institute,
      recruitProjectId: options.recruitProjectId,
      displayId: options.displayId
    })
    if(this.data.displayId==0){
      this.setData({
        projectType:0,
      })
    }else{
      this.setData({
        projectType:1
      })
    }
  },
  //提交展示
  submit(e){
    wx.request({
      url: 'https://www.hschuangsai.com/displayProject/add',
      header: {
        'content-type': 'application/json',
        'session': this.data.sessionID
      },
      data: {
        recruitProjectId: this.data.recruitProjectId,
        award: this.data.award ,
        captainName:this.data.captainName,
        innovation:this.data.innovation,
        institute:this.data.institute,
        introduction:this.data.introduction,
        major:this.data.major,
        memberFiveGrade	:this.data.memberFiveGrade,
        memberFiveMajor:this.data.memberFiveMajor,
        memberFiveName:this.data.memberFiveName,
        memberFourGrade:this.data.memberFourGrade,
        memberFourMajor	:this.data.memberFourMajor,
        memberFourName:this.data.memberFourName,
        memberOneGrade:this.data.memberOneGrade,
        memberOneMajor:this.data.memberOneMajor,
        memberOneName	:this.data.memberOneName,
        memberThreeGrade:this.data.memberThreeGrade,
        memberThreeMajor:this.data.memberThreeMajor,
        memberThreeName	:this.data.memberThreeName ,
        memberTwoGrade:this.data.memberTwoGrade,
        memberTwoMajor:this.data.memberTwoMajor,
        memberTwoName	:this.data.memberTwoName,
        name:this.data.name,
        number:this.data.number,
        paper:this.data.paper,
        teacherOneApartment:'教师院系',
        teacherOneName:this.data.teacherOneName,
        teacherOneRank:this.data.teacherOneRank,
        teacherOneStudy:this.data.teacherOneStudy,
        teacherTwoApartment:'教师院系',
        teacherTwoName:this.data.teacherTwoName,
        teacherTwoRank:this.data.teacherTwoRank,
        teacherTwoStudy:this.data.teacherTwoStudy,
        type:this.data.type,
        year: this.data.year,
        displayId:this.data.displayId,
        file: this.data.file,
        file2: this.data.file2,
        file2Name: this.data.file2Name,
        fileName: this.data.file1Name,
      },
      method: "POST",
      success: (result) => {
        console.log('after submit',result)
      },
    })
    wx.switchTab({
      url: '/pages/project/project'
    })
  },
  //附件上传
  upload(e){
    var that = this;
    wx.chooseMessageFile({
      count: 1,
      type: 'file',
      success: (result) => {
        var tempFilePaths = result.tempFiles[0]; 
        that.setData({
        　　　file1Name:tempFilePaths.name,
        })
        console.log(encodeURI(result.tempFiles[0].name))
        wx.uploadFile({
          url: 'https://www.hschuangsai.com/displayProject/upload',
          filePath: result.tempFiles[0].path,
          name: 'file', 
          method: 'POST',
          formData:{
            fileData: encodeURI(result.tempFiles[0].name),
            projectId:that.data.recruitProjectId,
            projectType: 0
          },
          header: {
          "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundarym9rNf7EsEiv7jdhu",
          'session': that.data.sessionID
          },
          success:function(res){
            var fileData = JSON.parse(res.data);
            that.setData({
              file: fileData.data 
            })
          }
        })
      },
    })

  },


//得到输入框数据
  getMajor(e){
    this.setData({
      major: e.detail.value
    })
  },
  getnumber(e){
    this.setData({
      number: e.detail.value
    })
  },
  getyear(e){
    this.setData({
      year: e.detail.value
    })
  },
  getname1(e){
    this.setData({
      memberOneName: e.detail.value
    })
  },
  getname2(e){
    this.setData({
      memberTwoName: e.detail.value
    })
  },
  getname3(e){
    this.setData({
      memberThreeName: e.detail.value
    })
  },
  getname4(e){
    this.setData({
      memberFourName: e.detail.value
    })
  },
  getname5(e){
    this.setData({
      memberFiveName: e.detail.value
    })
  },
  getgrade1(e){
    this.setData({
      memberOneGrade: e.detail.value
    })
  },
  getgrade2(e){
    this.setData({
      memberTwoGrade: e.detail.value
    })
  },
  getgrade3(e){
    this.setData({
      memberThreeGrade: e.detail.value
    })
  },
  getgrade4(e){
    this.setData({
      memberFourGrade: e.detail.value
    })
  },
  getgrade5(e){
    this.setData({
      memberFiveGrade: e.detail.value
    })
  },
  getmajor1(e){
    this.setData({
      memberOneMajor: e.detail.value
    })
  },
  getmajor2(e){
    this.setData({
      memberTwoMajor: e.detail.value
    })
  },
  getmajor3(e){
    this.setData({
      memberThreeMajor: e.detail.value
    })
  },
  getmajor4(e){
    this.setData({
      memberFourMajor: e.detail.value
    })
  },
  getmajor5(e){
    this.setData({
      memberFiveMajor: e.detail.value
    })
  },
  getTeacherTwoName(e){
    this.setData({
      teacherTwoName: e.detail.value
    })
  },
  getTeacherOneRank(e){
    this.setData({
      teacherOneRank: e.detail.value
    })
  },
  getTeacherOneStudy(e){
    this.setData({
      teacherOneStudy: e.detail.value
    })
  },
  getTeacherOneName(e){
    this.setData({
      teacherOneName: e.detail.value
    })
  },
  getTeacherTwoRank(e){
    this.setData({
      teacherTwoRank: e.detail.value
    })
  },
  getTeacherTwoStudy(e){
    this.setData({
      teacherTwoStudy: e.detail.value
    })
  },
  getIntroduction(e){
    this.setData({
      introduction: e.detail.value
    })
  },
  getInnovation(e){
    this.setData({
      innovation: e.detail.value
    })
  },
  getAward(e){
    this.setData({
      award: e.detail.value
    })
  }, 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})
